package com.by.system.controller;

import com.by.common.core.bean.ResultBean;
import com.by.common.core.response.R;
import com.by.common.validate.V;
import com.by.system.entity.User;
import com.by.system.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/user")
    public ResultBean save(@Validated @RequestBody User user, BindingResult result) {
        V.validate(result);
        boolean rs = userService.save(user);
        return rs ? R.success("保存成功") : R.fail("保存失败");
    }

}
